package com.hangman;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Random;

import android.util.Log;

@SuppressWarnings("serial")
public class Category implements Serializable{
	private ArrayList<Task> allTasks;
	private String name;
	private Random random;

	public Category(String name) {
		this.name = name;		
		this.allTasks = new ArrayList<Task>();
	}
	
	public void addTask(Task newTask){
		allTasks.add(newTask);
	}
	public int getNumberOfTasks(){
		return allTasks.size();
	}
	
	public String getName(){
		return name;
	}
	
	public ArrayList<Task> getRandomTasks(int numberOfTasks){
		Log.i("Number of tasks", numberOfTasks+"");
		Collections.shuffle(allTasks);
		if(numberOfTasks >= allTasks.size()-1){			
			return allTasks;
		}
		else if(numberOfTasks <= allTasks.size()){
			ArrayList<Task> selection = new ArrayList<Task>();			
			int counter = 0;
			for(Task tmp : allTasks){
				if(counter < numberOfTasks){
					selection.add(tmp);
				}else break;
			}
			return selection;
		
		}return null;
	}
	
	public String toString(){
		return  name.substring(0, 1).toUpperCase() +name.substring(1) + ": " + getNumberOfTasks();
		
	}

}
